package zjc.bookkeeping.fragment.tools;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;

import zjc.bookkeeping.R;

/**
 * Custom implementation of the MarkerView.
 *
 * @author Philipp Jahoda
 */
@SuppressLint("ViewConstructor")
public class MyMarkerView extends MarkerView {

    private final TextView tvContent;
    private String year;
    private int month = 13;

    public MyMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);

        tvContent = findViewById(R.id.tvContent);
        tvContent.setTextColor(Color.parseColor("#ff999999"));
        tvContent.setTextSize(8f);
    }

    public MyMarkerView(Context context, int layoutResource, String year, int month) {
        super(context, layoutResource);
        this.year = year;
        this.month = month;
        tvContent = findViewById(R.id.tvContent);
        tvContent.setTextColor(Color.parseColor("#ff999999"));
        tvContent.setTextSize(8f);
    }

    public MyMarkerView(Context context, int layoutResource, String year) {
        super(context, layoutResource);
        this.year = year;
        tvContent = findViewById(R.id.tvContent);
        tvContent.setTextColor(Color.parseColor("#ff999999"));
        tvContent.setTextSize(8f);
    }

    // runs every time the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {

//        if (e instanceof CandleEntry) {
//
//            CandleEntry ce = (CandleEntry) e;
//
//            tvContent.setText(Utils.formatNumber(ce.getHigh(), 0, true));
//        } else {
//
//            tvContent.setText(Utils.formatNumber(e.getY(), 0, true));
//        }
        String y = "金额:" + e.getY();
        String x;
        if(month == 13){
            x = year + "年" + (int)e.getX() + "月";
        }else {
            x =  year + "-" + month + "-" + (int)e.getX();
        }
        tvContent.setText(x + "\n" + y);
        Log.e("tvcontent",y);
        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}
